class Solution {
public:
    int triangularSum(vector<int>& nums) {
        int n = nums.size();
        vector<int> ret = nums, num = nums;
        while (n >= 2) {
            for (int i = 0; i < n - 1; ++i) {
                ret[i] = (num[i] + num[i + 1]) % 10;
            }
            num = ret;
            n--;
        }
        return ret[0];
    }
};